package com.ysd.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.ysd.entity.User;
import com.ysd.service.UserUpdateService;
import com.ysd.util.Result;

@Controller
public class UserUpdateController {

	@Autowired
	private UserUpdateService userUpdateService;
	
	
	@RequestMapping("updateUser")
	@ResponseBody
	public String updateUser(@Valid User user,BindingResult bindingResult) {
		System.out.println(bindingResult.hasErrors());
		if(bindingResult.hasErrors()) {
			return Result.toClient("1", "修改失败请填入正确的手机号或邮箱", null, null);
		} else {
			int	n=userUpdateService.findUpdateUser(user);
			if(n>0) {
				return Result.toClient("0", "修改成功",null);
			} else {
				return Result.toClient("1", "修改失败",null);
			}
		}
	}
	
	
	
}
